{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bdadb405",
   "metadata": {},
   "source": [
    "-------\n",
    "* 日期：2022-09-21\\weeko5（周三）\n",
    "* 课程：Python\n",
    "* 记录人：Zhoubilian"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a67f0c4",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "> 1.数值(number)\n",
    ">> 1.定义\n",
    ">> 2.方法\n",
    "\n",
    "> 2.字符串\n",
    ">> 1.定义\n",
    ">> 2.方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8638ee55",
   "metadata": {},
   "source": [
    "## 1.数值\n",
    "\n",
    "> 1.对数值进行分类\n",
    ">> 1.整数（int）\n",
    ">> 2.浮点型(float)\n",
    ">> 3.复数（complex）\n",
    "\n",
    "> 2.数值的运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a0fbd475",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整型\n",
    "a=99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6de77ef5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b=99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "47a2f431",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c=a+b\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7ad0f805",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数(虚数)\n",
    "d=2+3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "407990d7",
   "metadata": {},
   "source": [
    "## 2.字符串（str）\n",
    "> 1.定义\n",
    "\n",
    "> 2.方法 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f32e9348",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name='Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "605b0fb0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18 18\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a=18\n",
    "b='18'\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a04c4017",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 关于单引号和双引号\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "49767fb8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案2\\后面的内容是“符号”，转义，\\自动消失\n",
    "\"doesn\\'t\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "959928c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 正则表达式，有兴趣可以自学"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5d3597d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可以包括任何文本\n",
    "# 作用：\n",
    "# 1.保持原数据的结构，包含符号，换行等。\n",
    "# 2.可以用来做代码注释。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9890ac6",
   "metadata": {},
   "source": [
    "### 2.1字符串的运算法则\n",
    "> 1.字符串的拼接\n",
    "\n",
    "> 2.<font color=\"red\">字符串的有序性</font>\n",
    ">> 1.取值\n",
    ">> 2.切片\n",
    "\n",
    "> 3.in可以查询成员对象是否存在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a2582d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的拼接\n",
    "\"hello\"+\"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "bef3a063",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好Alex\n",
      "你好Marry\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "text=\"你好\"\n",
    "for i in [\"Alex\",\"Marry\"]:\n",
    "    result=text+i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92310e7c",
   "metadata": {},
   "source": [
    "## 2.2取值\n",
    "> 1.取单个值\n",
    "\n",
    "> 2.切片，取多个连续的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9ef442b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的有序性\n",
    "地址=\"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a858cbe0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a421d3e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "2f13ee23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "bb676b86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f231d8f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5606339f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在广州这个文本\n",
      "存在广州这个文本\n"
     ]
    }
   ],
   "source": [
    "# 实践：请检查广州是否在地址里面\n",
    "# 检查i是否是广，然后判断i下一个索引值得内容是否是州\n",
    "\n",
    "# 方法：enumerate:枚举\n",
    "for index,value in enumerate(地址):\n",
    "    if value==\"广\":\n",
    "        if 地址[index+1]==\"州\":\n",
    "            print(\"存在广州这个文本\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "a306ccbd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 方法：in 可以查询成员变量的\n",
    "print(\"广州\"in 地址)\n",
    "print(\"Alex\"in 地址)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
